//
//  NSObject+Honda.m
//  Honda
//
//  Created by Wang.Xinlei on 4/9/13.
//  Copyright (c) 2013 HeninHoo. All rights reserved.
//

#import "NSObject+Honda.h"

#import "NSArray+Honda.h"

@implementation NSObject (Honda)

+ (BOOL)valid:(id)object {
    return (nil != object && [object isKindOfClass:self]);
}

+ (BOOL)invalid:(id)object {
    return (nil == object || ![object isKindOfClass:self]);
}

#pragma mark - ValuesForKey
- (NSArray *)valuesForComponents:(NSArray *)components {
    return nil;
}

- (id)lastValueForPath:(NSArray *)components {
    return [self valuesForComponents:components].lastObject;
}

- (id)firstValueForPath:(NSArray *)components {
    return [self valuesForComponents:components].firstObject;
}

- (id)valueForComponents:(NSArray *)components atIndex:(NSUInteger)index {
    return [[self valuesForComponents:components] nilOrObjectAtIndex:index];
}

@end


NSString * NSStringFromObject(id object) {
    if ([NSObject invalid:object]) {
        return nil;
    }
    
    return [object description];
}
